package com.gccloud.tgyfirst.service.bro.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gccloud.starter.common.dto.SearchDTO;
import com.gccloud.starter.mybatis.page.PageVO;
import com.gccloud.starter.mybatis.utils.QueryWrapperUtils;
import com.gccloud.tgyfirst.bro.entity.BroEntity;
import com.gccloud.tgyfirst.service.bro.dao.BroDao;
import com.gccloud.tgyfirst.service.bro.service.IBroService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BroServiceImpl extends ServiceImpl<BroDao, BroEntity> implements IBroService {

    @Resource
    private BroDao broDao;



    @Override
    public List<BroEntity> queryAllQx(BroEntity broEntity) {
        LambdaQueryWrapper<BroEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BroEntity::getName,broEntity.getName());
        return listWithDp(queryWrapper);

    }
    @Override
    public PageVO<BroEntity> getPage(SearchDTO searchDTO) {
        LambdaQueryWrapper<BroEntity> queryWrapper = QueryWrapperUtils.wrapperLike
                (new LambdaQueryWrapper<>(), searchDTO.getSearchKey(), BroEntity::getName);
        return pageWithDp(searchDTO,queryWrapper);
    }

    @Override
    public void add(BroEntity broEntity) {
        this.save(broEntity);
    }

    @Override
    public void upd(BroEntity broEntity) {
        updateByIdWithDp(broEntity);
    }

    @Override
    public void del(String Id) {
        deleteByIdWithDp(Id);
    }

    @Override
    public Map<String, Object> queryAll(BroEntity broEntity) {
        Map<String,Object> map = new HashMap<String,Object>();
        List<BroEntity> list = broDao.queryAll(broEntity);
        map.put("code",0);
        map.put("msg","");
        map.put("count",list.size());
        map.put("data",list);
        return map;
    }



}
